/**
 * related to main.ui
 * 
 * @Author : lily80239464
 * @Timestamp : 2017-11-13
 */
var do_App = sm("do_App")
var nf = sm("do_Notification");
var do_Page = sm("do_Page");
var do_DataCache = sm("do_DataCache");
var do_ImageView_weather = ui("do_ImageView_weather");
var do_Label_now = ui("do_Label_now");
var do_Label_daily = ui("do_Label_daily");
var do_Label_rax = ui("do_Label_rax");
var do_Label_air = ui("do_Label_air");
var http = mm("do_Http");
var numHttp = mm("do_Http");
var do_ALayout_todo = ui("do_ALayout_todo");
var do_ALayout_receipt = ui("do_ALayout_receipt");
var do_ALayout_incomingRecord = ui("do_ALayout_incomingrecord");
var do_Label_num = ui("do_Label_num");
do_Label_num.visible = false;
//获取存储的数据
var baseUrl = do_DataCache.loadData("baseUrl");
var bean = do_DataCache.loadData("loginer");
//天气的http
http.method = "GET";
http.timeout=10000;
http.contentType="application/json";
http.url = "https://free-api.heweather.com/s6/weather?location=临洮&key=148d817bfb80414583348dc8a151334f";
//未读数量的http
numHttp.timeout=10000;
numHttp.contentType="application/x-www-form-urlencoded";
numHttp.url = baseUrl+"GetGDinfoUnFinish?User_id="+bean.returnObj[0].User_id;

//天气预报和未读数量获取
do_Page.on("loaded", function(data, e) {
	deviceone.print("12");
	http.on("success", function(data, e) {
		var imageCode = data.HeWeather6[0].now.cond_code
		do_ImageView_weather.source="source://image/a"+imageCode+".png";
		do_Label_now.text = data.HeWeather6[0].now.tmp+"℃ "+data.HeWeather6[0].now.cond_txt+" "+data.HeWeather6[0].now.wind_dir+data.HeWeather6[0].now.wind_sc;
		do_Label_daily.text = "白天"+data.HeWeather6[0].daily_forecast[0].cond_txt_d+" 夜间"+data.HeWeather6[0].daily_forecast[0].cond_txt_n
		+" "+data.HeWeather6[0].daily_forecast[0].tmp_min+"~"+data.HeWeather6[0].daily_forecast[0].tmp_max+"℃";
		do_Label_rax.text="紫外线强度指数"+data.HeWeather6[0].daily_forecast[0].uv_index;
		do_Label_air.text = "空气质量状况"+data.HeWeather6[0].lifestyle[7].brf;
		
	});
	http.on("fail", function(data, e) {
		
	});
	http.request();
	//获取未读数量
	deviceone.print(numHttp.url);
	numHttp.on("success", function(data, e) {
		var jsonString = data.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">","");
		jsonString = jsonString.replace("</string>","");
		var bean = JSON.parse(jsonString);
		if (bean.result==200) {
			do_Label_num.visible = true;
			do_Label_num.text = bean.returnObj.length;
		}else {
			nf.toast(bean.msg);
			do_Label_num.visible = false;
		}
	});
	numHttp.on("fail",function(data, e) {
		
	});
	numHttp.request();
	
	
});
//按钮切换
do_ALayout_todo.on("touch",function(data, e) {
	do_App.openPage({source: "source://view/todoReceipt/todoreceipt.ui", animationType:"push_t2b", statusBarState:"transparent"});
});
do_ALayout_receipt.on("touch",function(data, e) {
	do_App.openPage({source: "source://view/AllReceipt/allreceipt.ui", animationType:"push_t2b", statusBarState:"transparent"});
});
do_ALayout_incomingRecord.on("touch",function(data, e) {
	do_App.openPage({source: "source://view/incomingRecord/incomingrecord.ui", animationType:"push_t2b", statusBarState:"transparent"});
});
